package com.zhudoo.zhilian.util.service;

import com.zhudoo.zhilian.service.ChatService;
import com.zhudoo.zhilian.util.DateUtil;
import com.zhudoo.zhilian.util.MD5Util;

import java.util.Date;

/**
 * @author zhudao
 */
public class ChatUtil {


    public static String getContent(Integer contentType, String content) {
        //如果是文本
        if (contentType.equals(ChatService.text)) {
            return content;
        } else if (contentType.equals(ChatService.img)) {
            return "图片";
        } else if (contentType.equals(ChatService.map)) {
            return "地图";
        } else if (contentType.equals(ChatService.appointment)) {
            return "约看";
        }
        return "";
    }


    public static String getDateContent(String content, Date createTime) {
        String createTimeStr = DateUtil.parseToString(createTime, DateUtil.DATEFORMAT_YYYYMMDD);
        if (createTimeStr.equals(DateUtil.parseToString(new Date(), DateUtil.DATEFORMAT_YYYYMMDD))) {
            return content;
        } else {
            String createTimeMmDd = DateUtil.parseToString(createTime, DateUtil.DATEFORMAT_MMDD);
            return createTimeMmDd + " " + content;
        }
    }


    public static String getSessionId(Integer userId, Integer toUserId, Integer tipId) {
        return userId + "-" + toUserId + "-" + tipId;
    }

    public static Object getChatUpdateTime(Date updateTime) {
        String ymd = DateUtil.parseToString(updateTime, DateUtil.DATEFORMAT_YYYYMMDD);
        String hms = DateUtil.parseToString(updateTime, DateUtil.DATEFORMAT_HHMMSS);
        String nowYmd = DateUtil.parseToString(new Date(), DateUtil.DATEFORMAT_YYYYMMDD);
        if (ymd.equals(nowYmd)) {
            return hms;
        } else {
            return ymd;
        }

    }

    public static String getOnlyStr(Integer userId, Integer toUserId, Date appointmentDate, String address, String name, String phone) {
        String str = userId + "-" + toUserId + "-" + appointmentDate + "-" + address + "-" + name + "-" + phone;
        return MD5Util.md5Encode(str);
    }
}
